home *** CD-ROM | disk | FTP | other *** search
/ PC World Interactive 7 / PC World Interactive 7.iso / program / ctutor.exe / SOURCE / LOTTYPES.C < prev    next >
C/C++ Source or Header  |  1994-05-15  |  2KB  |  75 lines

  1.                              /* Chapter 4 - Program 3 - LOTTYPES.C */
  2. void main()
  3. {
  4. int a;              /* simple integer type                  */
  5. long int b;         /* long integer type                    */
  6. short int c;        /* short integer type                   */
  7. unsigned int d;     /* unsigned integer type                */
  8. char e;             /* character type                       */
  9. float f;            /* floating point type                  */
  10. double g;           /* double precision floating point      */
  11.  
  12.    a = 1023;
  13.    b = 2222;
  14.    c = 123;
  15.    d = 1234;
  16.    e = 'X';
  17.    f = 3.14159;
  18.    g = 3.1415926535898;
  19.  
  20.    printf("a = %d\n", a);      /* decimal output             */
  21.    printf("a = %o\n", a);      /* octal output               */
  22.    printf("a = %x\n", a);      /* hexadecimal output         */
  23.    printf("b = %ld\n", b);     /* decimal long output        */
  24.    printf("c = %d\n", c);      /* decimal short output       */
  25.    printf("d = %u\n", d);      /* unsigned output            */
  26.    printf("e = %c\n", e);      /* character output           */
  27.    printf("f = %f\n", f);      /* floating output            */
  28.    printf("g = %f\n", g);      /* double float output        */
  29.  
  30.    printf("\n");
  31.    printf("a = %d\n", a);      /* simple int output          */
  32.    printf("a = %7d\n", a);     /* use a field width of 7     */
  33.    printf("a = %-7d\n", a);    /* left justify in field of 7 */
  34.  
  35.    c = 5;
  36.    d = 8;
  37.    printf("a = %*d\n", c, a);  /* use a field width of 5     */
  38.    printf("a = %*d\n", d, a);  /* use a field width of 8     */
  39.  
  40.    printf("\n");
  41.    printf("f = %f\n", f);      /* simple float output        */
  42.    printf("f = %12f\n", f);    /* use field width of 12      */
  43.    printf("f = %12.3f\n", f);  /* use 3 decimal places       */
  44.    printf("f = %12.5f\n", f);  /* use 5 decimal places       */
  45.    printf("f = %-12.5f\n", f); /* left justify in field      */
  46. }
  47.  
  48.  
  49.  
  50. /* Result of execution
  51.  
  52. a = 1023
  53. a = 1777
  54. a = 3ff
  55. b = 2222
  56. c = 123
  57. d = 1234
  58. e = X
  59. f = 3.141590
  60. g = 3.141593
  61.  
  62. a = 1023
  63. a =    1023
  64. a = 1023
  65. a =  1023
  66. a =     1023
  67.  
  68. f = 3.141590
  69. f =     3.141590
  70. f =        3.142
  71. f =      3.14159
  72. f = 3.14159
  73.  
  74. */
  75.